<%--
  - Author		:	Jaewon Choi
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="/WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="/WEB-INF/pages/includes/doctype.jspf" %>
<c:choose>
	<c:when test="${not empty guide}">
		<c:set var="fAct" value="수정" />
	</c:when>
	<c:otherwise>
		<c:set var="fAct" value="등록" />
	</c:otherwise>
</c:choose>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirStyles}/common.css" />" />

		<link rel="stylesheet" type="text/css" href="<c:url value="${dirScripts}/jqueryUi/css/ui-lightness/jquery-ui-1.8.21.custom.css" />" />

		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-ui-1.8.21.custom.min.js" />"></script>
		<script type="text/javascript">
			$(function(){
				$("#name").focus();
				
				$( ".date" ).datepicker({
					showOn: "both",
					buttonImage: "<c:url value="${dirImages}/calendar.png" />",
					buttonImageOnly: true,
					dateFormat: "yy-mm-dd",
					showWeek: true
				});
			});
			
			function chkContNm(){
				var idx = "0";
				var name = document.frm.name.value;
				if(document.frm.idx){
					idx = document.frm.idx.value;
				}
				
				$.ajax({
					type: "POST",
					url: "<c:url value="/content/chkDupl" />",
					dataType: "json",
					async: false,
					data: {
								"idx" : idx,
								"chkName" : name
							},
					success: function(data){
						if(data.resultCode == "200"){
							chkContNmFlag = data.result;
							if(eval(chkContNmFlag)){
								$(document.frm.name).css("background", "#ADC900");
							}else{
								$(document.frm.name).css("background", "#F2685E");
							}
						}else{
							alert(data.errMsg);
						}
					},
					beforeSend: function(){
					},
					error: function(jqXHR, textStatus, errorThrown){
						//alert(jqXHR.responseText); //에러 페이지 내용
						alert("오류가 발생하였습니다.\n관리자에게 문의 바랍니다.");
						throw errorThrown;
					},
					complete: function(){
					}
				 });
				return eval(chkContNmFlag);
			}
			
			/*
			 * 숫자(정수) 형식 여부
			 */
			function isOnlyNumber(source) {
				var pattern = /^[0-9]+$/;
				
				return pattern.test(source);
			}
			
			function validation(){
				try{
					
				}catch(err){
					return false;	
				}
				
				return confirm("${fAct} 하시겠습니까?");
			}
		</script>
	</head>
	<body>
		<div class="bodyWrap">
<%@ include file="/WEB-INF/pages/includes/header.jsp" %>
<%@ include file="/WEB-INF/pages/includes/left.jsp" %>
			<div class="contWrap">
				<div class="menuTitle">
					이용안내${fAct}
				</div>
				<form id="frm" name="frm" method="post" enctype="multipart/form-data" action="<c:url value="/guide/submit.do" />" onsubmit="return validation();">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="startDate" value="${param.startDate}" /> 
					<input type="hidden" name="endDate" value="${param.endDate}" />
					<input type="hidden" name="searchName" value="${param.searchName}" />
					<input type="hidden" name="searchCategoryId" value="${param.searchCategoryId}" />
					<input type="hidden" name="title" value="이용안내" />
					<input type="hidden" name="cont" value="이용안내" />
					<input type="hidden" name="gubun" value="guide" />
					<input type="hidden" name="idx" value="${guide.idx}">
					
					<table class="frmTbl">
						<colgroup>
							<col width="176px;" />
							<col width="*" />
							<col width="100px;" />
							<col width="*" />
						</colgroup>
						<tbody>
							<tr>
								<th rowspan="12" colspan=3>이용안내(이미지)</th>
							</tr>
							<c:forEach var="guideImg" items="${guideImgs}" varStatus="stat">
							<c:set var="j" value="${j+1}" />
								<tr>
									<td colspan=3>
										<!-- <input type="checkbox" name="guideFileIdx" value="${guideImg.idx}" /> -->
										<input type="file" name="guideFiles[${j-1}]" />
										<input type="hidden" name="guideFileTypes" value="guideImg" />
										<input type="hidden" name="guideFileDatas" value="${j-1}" />
										<br /><img src="${guideImg.fileUrl}" class="thumbnailImg" />
									</td>
								</tr>
							</c:forEach>
							<c:forEach var="i" begin="0" end="${9-fn:length(guideImgs)}" step="1" varStatus="stat">
								<tr>
									<td colspan=3>
										<input type="file" name="guideFiles[${i+j}]" />
										<input type="hidden" name="guideFileTypes" value="guideImg" />
										<input type="hidden" name="guideFileDatas" value="${i+j}" />
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<input type="submit" class="btn" value="${fAct}" />
				</form>
			</div>
<%@ include file="/WEB-INF/pages/includes/footer.jsp" %>
		</div>
	</body>
</html> 